﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace PHTShop.admin
{
    public partial class theme : System.Web.UI.Page
    {
        private DataContextDataContext dc = new DataContextDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "Change theme";
            if (!IsPostBack)
            {
                load();
                

            }
        }
        private void load() {
            var theme = dc.Settings.SingleOrDefault(z=>z.type.Equals("theme") && z.value.Equals("1"));

            RadioButtonList1.DataSource = dc.Settings.Where(z => z.type.Equals("theme"));
            RadioButtonList1.DataTextField = "name";
            RadioButtonList1.DataValueField = "id";

            RadioButtonList1.DataBind();
            RadioButtonList1.Items.FindByValue(theme.id.ToString()).Selected = true;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {

            if (RadioButtonList1.SelectedIndex>-1)
            {
                foreach (ListItem item in RadioButtonList1.Items)
                {
                    if (item.Selected)
                    {
                        var s = dc.Settings.SingleOrDefault(z => z.type.Equals("theme") && z.name == item.Text);
                        s.value = "1";
                        dc.SubmitChanges();
                    }

                    else {
                        var s = dc.Settings.SingleOrDefault(z => z.type.Equals("theme") && z.name == item.Text);
                        s.value = "0";
                        dc.SubmitChanges();
                    
                    }
                }
            }
           
        }

        
    }
}